package com.genshang.restaurant.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.genshang.restaurant.entity.Customerlist;
import com.genshang.restaurant.mapper.CustomerlistMapper;
import com.genshang.restaurant.result.ResultBody;
import com.genshang.restaurant.service.ICustomerlistService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author Alex
 * @since 2020-07-28
 */
@Service
public class CustomerlistServiceImpl extends ServiceImpl<CustomerlistMapper, Customerlist> implements ICustomerlistService {

    @Override
    public Customerlist getCustomerByPhone(String phone) {
        QueryWrapper<Customerlist> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("PHONE", phone);
        Customerlist customerlist = this.getOne(queryWrapper);
        return customerlist;
    }

    @Override
    public ResultBody getTotalScores(String phone) {
        Customerlist customerlist = this.getCustomerByPhone(phone);
        if (null == customerlist) {
            return ResultBody.error("未找到用户");
        }
        return ResultBody.success(customerlist.getTotalscores());
    }
}
